<?php
header ( 'content-type:text/html; charset=utf-8' );

session_start();

@$userid = $_SESSION['userid'];

if (empty($userid)){
	die(json_encode(array('status'=>false,'info'=>'tips：操作超时　请重新登录')));
}

@$outcash = $_REQUEST['money'];

require 'lib/db.php';

@$user = dbselect('select money from user where id=:id',array('id'=>$userid));

if (empty($outcash)){
	die(json_encode(array('status'=>false,'info'=>'tips：取款金额不能为空　你是搞到耍的？')));
}

if (!is_numeric($outcash)){
	die(json_encode(array('status'=>false,'info'=>'tips：取款金额只能为数字　难道你输入“老婆” 还能取个“老婆”出来？')));
}

if ($outcash<0){
	die(json_encode(array('status'=>false,'info'=>'tips：取款金额不能为负数　难道你是想存钱？')));
}

if ($outcash>$user['money']){
	die(json_encode(array('status'=>false,'info'=>'tips：你的余额只有：'.$user['money'].' 你为的什么想取：'.$outcash)));
}

@$flag = dbupdate('update user set money=money-:outcash where id=:id',array('outcash'=>$outcash,'id'=>$userid));

if (!$flag){
	die(json_encode(array('status'=>false,'info'=>'tips：取款失败')));
}

echo json_encode(array('status'=>true,'money'=>$user['money']-$outcash));